home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / C-D / DartmouthXCMDs.cpt / Dartmouth XCMDs Vol 1&2 / card_11661.txt < prev    next >
Text File  |  1989-02-26  |  15KB  |  455 lines

  1. -- card: 11661 from stack: in
  2. -- bmap block id: 11899
  3. -- flags: 0000
  4. -- background id: 8327
  5. -- name: LSC Utilities
  6. ----- HyperTalk script -----
  7. on opencard
  8.   set the visible of field 1 to false -- background field
  9.   set the visible of card field "oh well" to false
  10.   set the scroll of card field 1 to 0
  11.   set the visible of button "put" to false
  12.   set the visible of button "get" to false
  13. end opencard
  14. on closecard
  15.   set the visible of field 1 to true
  16. end closecard
  17.  
  18.  
  19. -- part 5 (field)
  20. -- low flags: 01
  21. -- high flags: 2007
  22. -- rect: left=18 top=32 right=290 bottom=486
  23. -- title width / last selected line: 0
  24. -- icon id / first selected line: 0 / 0
  25. -- text alignment: 0
  26. -- font id: 20
  27. -- text size: 12
  28. -- style flags: 0
  29. -- line height: 16
  30. -- part name: XCMD Text
  31.  
  32.  
  33. -- part 6 (button)
  34. -- low flags: 00
  35. -- high flags: 8003
  36. -- rect: left=304 top=299 right=321 bottom=425
  37. -- title width / last selected line: 0
  38. -- icon id / first selected line: 0 / 0
  39. -- text alignment: 1
  40. -- font id: 0
  41. -- text size: 12
  42. -- style flags: 0
  43. -- line height: 16
  44. -- part name: Show LSC Source
  45. ----- HyperTalk script -----
  46. on mouseUp
  47.   get the visible of card field "source"
  48.   set the visible of card field "source" to not it
  49.   if it is false then
  50.     set the name of me to "Hide LSC Source"
  51.   else
  52.     set the name of me to "Show LSC Source"
  53.   end if
  54. end mouseUp
  55.  
  56.  
  57.  
  58. -- part 7 (field)
  59. -- low flags: 81
  60. -- high flags: 0007
  61. -- rect: left=18 top=31 right=291 bottom=486
  62. -- title width / last selected line: 0
  63. -- icon id / first selected line: 0 / 0
  64. -- text alignment: 0
  65. -- font id: 3
  66. -- text size: 10
  67. -- style flags: 0
  68. -- line height: 13
  69. -- part name: source
  70.  
  71.  
  72. -- part 8 (field)
  73. -- low flags: 80
  74. -- high flags: 0002
  75. -- rect: left=18 top=24 right=285 bottom=482
  76. -- title width / last selected line: 0
  77. -- icon id / first selected line: 0 / 0
  78. -- text alignment: 0
  79. -- font id: 0
  80. -- text size: 12
  81. -- style flags: 0
  82. -- line height: 16
  83. -- part name: oh well
  84.  
  85.  
  86. -- part 9 (button)
  87. -- low flags: 80
  88. -- high flags: 8003
  89. -- rect: left=154 top=289 right=307 bottom=189
  90. -- title width / last selected line: 0
  91. -- icon id / first selected line: 0 / 0
  92. -- text alignment: 1
  93. -- font id: 0
  94. -- text size: 12
  95. -- style flags: 0
  96. -- line height: 16
  97. -- part name: Put
  98. ----- HyperTalk script -----
  99. on mouseUp
  100.   -- You may have to change the parmater list to suit your configuration
  101.   -- NOTE: This button is a self contained operation of open, put,close.
  102.   --       You DO NOT have to open and close every time you get or put.
  103.   --       Just open once and start once, like when you open and close
  104.   --       your stack.
  105.   get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  106.   if it is not empty then
  107.     put "Error: "&&it&&" (See script of "put" button)"
  108.   end if
  109.   get Serialhandler("put","A",the script of me)
  110.   if it is not empty then
  111.     put "Error: "&&it
  112.   end if
  113.   get Serialhandler("close","A")
  114. end mouseUp
  115.  
  116.  
  117.  
  118. -- part 10 (button)
  119. -- low flags: 80
  120. -- high flags: 8003
  121. -- rect: left=187 top=306 right=324 bottom=223
  122. -- title width / last selected line: 0
  123. -- icon id / first selected line: 0 / 0
  124. -- text alignment: 1
  125. -- font id: 0
  126. -- text size: 12
  127. -- style flags: 0
  128. -- line height: 16
  129. -- part name: Get
  130. ----- HyperTalk script -----
  131. on mouseUp
  132.   -- You may have to change the parmater list to suit your configuration
  133.   -- NOTE: This button is a self contained operation of open, put,close.
  134.   --       You DO NOT have to open and close every time you get or put.
  135.   --       Just open once and start once, like when you open and close
  136.   --       your stack.
  137.   get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  138.   set the visible of card field "got" to true
  139.   put empty into card field "got"
  140.   put "Click the mouse when done."
  141.   repeat while the mouse is up
  142.     get SerialHandler("get","A",60)
  143.     put it after card field "got"
  144.   end repeat
  145.   get SerialHandler("close","A")
  146.   set the visible of card field "got" to false
  147.   put empty into msg
  148. end mouseUp
  149.  
  150.  
  151.  
  152. -- part 11 (field)
  153. -- low flags: 80
  154. -- high flags: 0007
  155. -- rect: left=18 top=32 right=285 bottom=481
  156. -- title width / last selected line: 0
  157. -- icon id / first selected line: 0 / 0
  158. -- text alignment: 0
  159. -- font id: 3
  160. -- text size: 12
  161. -- style flags: 0
  162. -- line height: 16
  163. -- part name: got
  164.  
  165.  
  166. -- part contents for card part 5
  167. ----- text -----
  168. LSC Utilities
  169. Roger Brown
  170.  
  171. This is a collection of various C functions that are useful when creating XFCNs.
  172. They are written in LightSpeed C.
  173.  
  174. Included are:
  175.  
  176. ‚Ä¢ Number of HyperCard Items : int NumHCitems(char *source)
  177.    Given a pointer to a source of HyperCard formatted items (comma delimited),  return the     
  178.    number of items in it.
  179.  
  180. ‚Ä¢ Get HyperCard Item  : GetHCItem(char *inStr,  int i,  char *outStr)
  181.   Given a HyperCard item list (comma delimited) in string inStr, get item i and return it
  182.   as a string in outStr.
  183.  
  184. ‚Ä¢ Number of HyperCard Lines : int NumHCLines(char *source)
  185.    Given a pointer to a source of HyperCard formatted lines, such as a field, return the     
  186.    number of lines in it.
  187.  
  188. ‚Ä¢ Get HyperCard Line : GetHCLine(int ine,  char *source,  char *dest)
  189.   Given a pointer to a source of lines (like a field), extract the requested line and return it
  190.   in string dest.
  191.  
  192. ‚Ä¢ Get HyperCard Expression : GetHCExpression(char *inStr,  char *outStr)
  193.   Given a HyperCard expression in inString, return its value in outStr.
  194.  
  195. ‚Ä¢ String Contains : StrContains(char *target,  char *test)
  196.    Given string test, return TRUE if it contains the string target.
  197.  
  198. ‚Ä¢ Get HyperCard Rectangle : GetCardRect(Rect *itsRect)
  199.   Get the rectangle of HyperCard's card window.
  200.  
  201. ‚Ä¢ Build a return result : ResultIs(XCmdBlockPtr paramPtr,  char *theResult)
  202.    Given a C formatted string, build a return result structure for the given parameter block.
  203.  
  204. -- part contents for card part 7
  205. ----- text -----
  206. /* HCLib1.0a1.c */
  207. /* ¬© Trustees of Dartmouth College */
  208. /* written in LightSpeed C  ¬© Think Technologies, Inc */
  209. /* by Roger Brown 7/7/88  Courseware Development group */
  210. /* HyperCard XCMD support library */
  211.  
  212.  
  213. #include "QuickDraw.h"
  214. #include "FontMgr.h"
  215. #include "EventMgr.h"
  216. #include "WindowMgr.h"
  217. #include "MenuMgr.h"
  218. #include "MemoryMgr.h"
  219. #include "ResourceMgr.h"
  220. #include "ToolboxUtil.h"
  221. #include "ControlMgr.h"
  222. #include "DialogMgr.h"
  223. #include "HyperXCmd.h"
  224. #include "XCmdGlue.inc.c"
  225.  
  226. /* Get the number of HyperCard comma delimited items in string s. */
  227.  
  228. int NumHCItems(s)
  229. char *s;
  230. {
  231.     int c;                                           /* character pointer */
  232.     int len;                                         /* length of string */
  233.     int count;                                       /* count of items found */
  234.     int j;                                           /* item byte counter */  
  235.     
  236.     count = j = 0;                                   /* initialize */
  237.     len = strlen(s);                                 /* will look this far */
  238.     for (c=0;c<len;c++) {                            /* scan all characters */
  239.         if (s[c]==',') {                             /* found end of an item */
  240.             count = count + 1;                       /* bump item found counter */
  241.             j = 0;                                   /* reset item scan counter */
  242.         }
  243.         else {                                       
  244.             j++;                                     /* bump item byte counter */
  245.             if (c==(len-1)) {                        /* last item, no comma */
  246.                 count = count+1;                     /* this one counts, too */
  247.                 break;
  248.             }
  249.         }
  250.     }
  251.     return count;
  252. }
  253.  
  254. /* Get HyperCard comma delimited item i from item list string inStr. Return it in outStr */
  255. /* item must be smaller than 255 characters */
  256.  
  257. GetHCItem(inStr,i,outStr)
  258. char *inStr,*outStr;
  259. int i;
  260. {
  261.     int c;                                           /* character pointer */
  262.     int len;                                         /* length to scan */
  263.     int count;                                       /* count of items found */
  264.     int j;                                           /* item byte count */
  265.     Str255 temp;                                     /* collect item here, hope its < 255 */
  266.     
  267.     count = j = 0;                                   /* initialize */
  268.     len = strlen(inStr);                             /* go this far, max */
  269.     for (c=0;c<len;c++) {
  270.         if (inStr[c]==',') {                         /* at an item boundary */
  271.             count = count + 1;                       /* bump counter */
  272.             if (count==i) break;                     /* if this is it, stop scanning */
  273.             j = 0;                                   /* else start on the next item */
  274.         }
  275.         else {
  276.             temp[j] = inStr[c];                      /* collect characters to return */
  277.             j++;                                     /* go to next */
  278.             if (j==255) {                            /* sorry, too big to store */
  279.                 strcpy(temp,"Error: Item > 255 characters.");
  280.                 return;                       
  281.             }
  282.             if (c==(len-1)) {                        /* last item, no comma */
  283.                 count = count+1;
  284.                 break;
  285.             }
  286.         }
  287.     }
  288.     if (count < i) strcpy(outStr,"Error: item out of range");   /* no item there */
  289.     else {
  290.         temp[j] = 0;                                     /* make it a C string */
  291.         strcpy(outStr,temp);                             /* move to output string */
  292.     }
  293.     return;
  294. }
  295.  
  296. /* how many HyperCard lines in string source  */
  297.  
  298. NumHCLines(source) 
  299. char *source;
  300. {
  301.     int c;                                           /* character counter */
  302.     int l;                                           /* line counter */
  303.     int len;
  304.     
  305.     len = strlen(source);
  306.     l = 0;
  307.     for (c=0;c<len;c++) {                            /* scan to desired line */
  308.         if (source[c]==13) l++;
  309.     }
  310.     if (source[c-1]!=13) l++;                        /* last line might not have CR */
  311.     return l;
  312.     
  313. }
  314. /* get HyperCard line from source and return in dest */
  315.  
  316. GetHCLine(line,source,dest)
  317. int line;
  318. char *source,*dest;
  319. {
  320.     int i;                                                /* char counter before line */
  321.     int j;                                                /* char cou,tner after line */
  322.     int c;                                                /* line counter */
  323.     int len;                                              /* length of source */
  324.             
  325.     len = strlen(source);                                 /* go this far, max */
  326.     c = 1;                                                /* initialize */
  327.     i = 0;
  328.     while (c<line) {                                      /* cycle to desired line */
  329.         if (source[i]==13) c++;                           /* bump line count */
  330.         i++;
  331.         if (i>len) {                                      /* out of range */
  332.             strcpy(dest,"Error: Line out of range."); 
  333.             return;
  334.         }
  335.     }
  336.     c = 0;                                                /* at line, start transfer */
  337.     for (j=i;j<len;j++) {
  338.         *(dest+c) = source[j];
  339.         if (source[j]==13) break;                         /* line ended */
  340.         c++;
  341.     }
  342.     *(dest+c) = (char)0;                                  /* make into a C string */
  343. }
  344.  
  345. /* Given a HyperCard expression in inStr, return its value in outStr */
  346.  
  347. GetHCExpression(paramPtr,inStr,outStr)
  348. XCmdBlockPtr    paramPtr;
  349. char *inStr;
  350. Str255 *outStr;
  351. {
  352.     Handle theResult;                                     /* handle to the final result */
  353.     long len;                                             /* length needed */
  354.     
  355.     strcpy(outStr,inStr);                    /* cheat a little, use outStr as an intermediate */
  356.     CtoPstr(outStr);                                      /* make it a P string */
  357.     theResult = EvalExpr(paramPtr,outStr);               /* get its value from HC */
  358.     len = GetHandleSize(theResult);                       /* how long is it? */
  359.     BlockMove(*theResult,outStr,len);                     /* move the result into outStr */
  360.     DisposHandle(theResult);                              /* tidy up */
  361. }
  362.  
  363. /* Return true if target string contains test string. Match is not case sensitive. */
  364.  
  365. char StrContains(target,test) 
  366. char *target,*test;
  367. {
  368.     char ok;
  369.     int i;
  370.     char *j,*k;
  371.     int targetLen,testLen;
  372.     char go;
  373.     
  374.     targetLen = strlen(target);                            /* scan this far, max */
  375.     testLen = strlen(test);                                /* look for this many matches */
  376.     for (i=0;i<targetLen;i++) { 
  377.         j = target+i;
  378.         k = test;
  379.         while (toupper(*j)==toupper(*k)) {                 /* loop while they match */
  380.             j++;
  381.             k++;
  382.             if (k==(test+testLen)) return TRUE;            /* got it */
  383.         }
  384.     }
  385.     return FALSE;                                          /* no match */
  386. }
  387.  
  388. /* Get the coordiates of the HyperCard card window */
  389.  
  390. GetCardRect(paramPtr,itsRect)
  391. XCmdBlockPtr    paramPtr;
  392. Rect *itsRect;
  393. {
  394.     Handle theResult;
  395.     long len,corner;
  396.     Str255 str,it;
  397.     int i;                                                 /* no comment */
  398.     
  399.     strcpy(str,"the rect of card window");
  400.     CtoPstr(str);
  401.     theResult = EvalExpr(paramPtr,str);
  402.     len = GetHandleSize(theResult);
  403.     HLock(theResult);
  404.     BlockMove(*theResult,str,len);
  405.     HUnlock(theResult);
  406.     DisposHandle(theResult);
  407.     
  408.     GetHCItem(str,1,it);
  409.     CtoPstr(it);
  410.     StringToNum(it,&corner);
  411.     itsRect->left = (int)corner;
  412.     GetHCItem(str,2,it);
  413.     CtoPstr(it);
  414.     StringToNum(it,&corner);
  415.     itsRect->top = (int)corner;
  416.     GetHCItem(str,3,it);
  417.     CtoPstr(it);
  418.     StringToNum(it,&corner);
  419.     itsRect->right = (int)corner;
  420.     GetHCItem(str,4,it);
  421.     CtoPstr(it);
  422.     StringToNum(it,&corner);
  423.     itsRect->bottom = (int)corner;
  424. }
  425.  
  426. /* build a return result structure from a string */
  427.  
  428. ResultIs(paramPtr,theResult)
  429. XCmdBlockPtr    paramPtr;
  430. char *theResult;
  431. {
  432.     long len;
  433.     Handle resultHandle;
  434.     len = 1+strlen(theResult);
  435.     resultHandle = NewHandle(len);
  436.     BlockMove(theResult,*resultHandle,len);
  437.     paramPtr->returnValue = resultHandle;
  438. }
  439.  
  440.  
  441.  
  442. -- part contents for card part 8
  443. ----- text -----
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.                           Alas, this demonstration will show you 
  452.                           nothing of interest unless you have a 
  453.                           serial device attached to your Mac. Like 
  454.                           an Imagewriter, or a terminal if you want 
  455.                           to get input.